#include "lib_sys_proc.h"
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>

int main()
{
    sys_cpuTime_t* last_sys_cpuTime, *now_sys_cpuTime;
    sys_cpuTime_t* sys_cpuTime_ptr = init_sys_cpuTime();
    if(sys_cpuTime_ptr == NULL)
    {
        printf("init_sys_cpuTime failed\n");
        return -1;
    }
    last_sys_cpuTime = sys_cpuTime_ptr;

    while(1)
    {
        sleep(1);
        now_sys_cpuTime = get_sys_cpuTime(sys_cpuTime_ptr);
        if(now_sys_cpuTime == NULL)
        {
            printf("get_sys_cpuTime failed\n");
            break;
        }
        cal_cpu_usage(last_sys_cpuTime, now_sys_cpuTime);
        show_cpu_usage(now_sys_cpuTime);

        // 重置索引
        last_sys_cpuTime = now_sys_cpuTime;
        now_sys_cpuTime = NULL;
    }
    free_sys_cpuTime(sys_cpuTime_ptr);

    return 0;
}